/*
 * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ice4j;

import org.ice4j.message.Message;
import org.ice4j.stack.StunStack;
import org.ice4j.stack.TransactionID;

/**
 * The class is used to dispatch events that occur when a STUN transaction
 * expires.
 *
 * @author Emil Ivov
 */
public class StunTimeoutEvent extends BaseStunMessageEvent {
	/**
	 * Serial version UID for this Serializable class.
	 */
	private static final long serialVersionUID = 41267841L;

	/**
	 * Constructs a <tt>StunTimeoutEvent</tt> according to the specified
	 * message.
	 *
	 * @param stunStack
	 *            the <tt>StunStack</tt> to be associated with the new instance
	 * @param message
	 *            the message itself
	 * @param localAddress
	 *            the local address that the message was sent from.
	 * @param transactionID
	 *            the ID of the associated with this event.
	 */
	public StunTimeoutEvent(StunStack stunStack, Message message, TransportAddress localAddress,
			TransactionID transactionID) {
		super(stunStack, localAddress, message);

		setTransactionID(transactionID);
	}

	/**
	 * Returns the <tt>TransportAddress</tt> that the message was supposed to
	 * leave from.
	 *
	 * @return the <tt>TransportAddress</tt> that the message was supposed to
	 *         leave from.
	 */
	public TransportAddress getLocalAddress() {
		return getSourceAddress();
	}

	/**
	 * Returns a <tt>String</tt> representation of this event, containing the
	 * corresponding message, and local address.
	 *
	 * @return a <tt>String</tt> representation of this event, containing the
	 *         corresponding message, and local address.
	 */
	@Override
	public String toString() {
		StringBuffer buff = new StringBuffer("StunTimeoutEvent:\n\tMessage=");

		buff.append(getMessage());
		buff.append(" localAddr=").append(getLocalAddress());

		return buff.toString();
	}
}
